package edu.towson.cosc603.coffeemaker;

import junit.framework.TestCase;

/**
 * Junit test for CoffeeMaker Class.
 */
public class CoffeeMakerTest extends TestCase {
	private CoffeeMaker cm;
	private Inventory i;
	private Recipe r1;
	private Recipe r2;
	private Recipe r3;
	private Recipe r4;
	private Recipe r5;
	
	/**
	 * Setup method to configure fixtures. 
	 */
	
	public void setUp() {
		cm = new CoffeeMaker();
		i = cm.checkInventory();

		r1 = new Recipe();
		r1.setName("Coffee");
		r1.setPrice(50);
		r1.setAmtCoffee(6);
		r1.setAmtMilk(1);
		r1.setAmtSugar(1);
		r1.setAmtChocolate(0);
		
		r2 = new Recipe();
		r2.setName("Mocha");
		r2.setPrice(50);
		r2.setAmtCoffee(100);
		r2.setAmtMilk(100);
		r2.setAmtSugar(100);
		r2.setAmtChocolate(100);

		r3 = new Recipe();
		r3.setName("Decaf");
		r3.setPrice(50);
		r3.setAmtCoffee(100);
		r3.setAmtMilk(100);
		r3.setAmtSugar(100);
		r3.setAmtChocolate(100);
		
		r4 = new Recipe();
		r4.setName("Vanilla");
		r4.setPrice(50);
		r4.setAmtCoffee(100);
		r4.setAmtMilk(100);
		r4.setAmtSugar(100);
		r4.setAmtChocolate(100);
		
		r5 = new Recipe();
		r5.setName("Latte");
		r5.setPrice(50);
		r5.setAmtCoffee(100);
		r5.setAmtMilk(100);
		r5.setAmtSugar(100);
		r5.setAmtChocolate(100);
	}

	/**
	 * Test for addRecipe method.
	 */

	public void testAddRecipe1() {
		assertTrue(cm.addRecipe(r1));
		assertFalse(cm.addRecipe(r1));
	}

	/**
	 * Test for addRecipe method.
	 */

	public void testAddRecipe2() {
		assertTrue(cm.addRecipe(r2));
		assertFalse(cm.addRecipe(r2));
	}

	/**
	 * Test for addRecipe method.
	 */

	public void testAddRecipe3() {
		assertTrue(cm.addRecipe(r3));
		assertFalse(cm.addRecipe(r3));
	}

	/**
	 * Test for addRecipe method..
	 */

	public void testAddRecipe4() {
		assertTrue(cm.addRecipe(r4));
		assertFalse(cm.addRecipe(r4));
	}

	/**
	 * Test for addRecipe method when full.
	 */

	public void testAddRecipe5False() {
		assertTrue(cm.addRecipe(r1));
		assertTrue(cm.addRecipe(r2));
		assertTrue(cm.addRecipe(r3));
		assertTrue(cm.addRecipe(r4));
		assertFalse(cm.addRecipe(r5));
	}


	/**
	 * Test for deleteRecipe method..
	 */

	public void testDeleteRecipe1() {
		cm.addRecipe(r1);
		assertTrue(cm.deleteRecipe(r1));
	}

	/**
	 * Test editRecipe method.
	 */
	public void testEditRecipe1() {
		cm.addRecipe(r1);
		cm.addRecipe(r2);
		cm.addRecipe(r3);
		Recipe newRecipe = new Recipe();
		newRecipe = r1;
		newRecipe.setAmtSugar(2);
		assertTrue(cm.editRecipe(r1, newRecipe));
		cm.addRecipe(r4);
		assertFalse(cm.editRecipe(r1, r2));
	}
	
	/**
	 * Test for editRecipe method when recipe not present.
	 */

	public void testEditNoRecipeFalse() {
		cm.addRecipe(r1);
		cm.addRecipe(r2);
		cm.addRecipe(r3);
		cm.addRecipe(r4);
		assertFalse(cm.editRecipe(r5, r5));
	}

	/**
	 * Test for addInventory method for coffee.
	 */

	public void testAddInventoryCoffee() {
		assertTrue(cm.addInventory(10,0,0,0));	
		i = cm.checkInventory();
		assertEquals(25, i.getCoffee());
		assertFalse(cm.addInventory(-1, 0, 0, 0));
	}
	
	/**
	 * Test for addInventory method for milk.
	 */
	
	public void testAddInventoryMilk() {
		assertTrue(cm.addInventory(0,10,0,0));
		i = cm.checkInventory();
		assertEquals(25, i.getMilk());
		assertFalse(cm.addInventory(0, -1, 0, 0));
	}
	
	/**
	 * Test for addInventory method for Chocolate.
	 */
	public void testAddInventoryChocolate() {
		assertTrue(cm.addInventory(0,0,0,10));	
		i = cm.checkInventory();
		assertEquals(25, i.getChocolate());
		assertFalse(cm.addInventory(0, 0, -1, 0));
	}
	
	/**
	 * Test for addInventory method for sugar.
	 */
	public void testAddInventorySugar() {
		assertTrue(cm.addInventory(0,0,10,0));
		i = cm.checkInventory();
		assertEquals(25, i.getSugar());
		assertFalse(cm.addInventory(0, 0, 0, -1));
	}
	
	/**
	 * Test for purchaseBeverage method for coffee.
	 */
	public void testPurchaseBeverage() {
		assertEquals(0, cm.makeCoffee(r1, 50));
		assertEquals(9, i.getCoffee());
		assertEquals(14, i.getMilk());
		assertEquals(14, i.getSugar());
		assertEquals(15, i.getChocolate());
		assertEquals(25, cm.makeCoffee(r1, 25));
		cm.addRecipe(r2);
		assertEquals(50, cm.makeCoffee(r2, 50));
	}
	
	/**
	 * Test for getRecipeName method for coffee.
	 */
	public void testRecipieName() {
		cm.addRecipe(r1);
		assertEquals(r1, cm.getRecipeForName("Coffee"));
	}
	
	/**
	 * Test for gerRecipes method.
	 */
	public void testRecipeArray() {
		Recipe[] recipes = new Recipe[4];
		recipes[0] = r1;
		recipes[1] = r2;
		recipes[2] = r3;
		recipes[3] = r4;
		cm.addRecipe(r4);
		cm.addRecipe(r3);
		cm.addRecipe(r2);
		cm.addRecipe(r1);
		Recipe[] cmRecipes = cm.getRecipes();
		assertEquals(recipes[0],cmRecipes[0]);
		assertEquals(recipes[1],cmRecipes[1]);
		assertEquals(recipes[2],cmRecipes[2]);
		assertEquals(recipes[3],cmRecipes[3]);
	}
	
	
}